<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-spin :spinning="confirmLoading">
      <a-form>
        <a-form-item :labelCol="labelCol" :wrapperCol="labelCol" label="订单编号">
          <a-input disabled v-model="templateOrderId" />
        </a-form-item>
        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="订单退款理由">
          <a-textarea disabled v-model="templateContent"  />
        </a-form-item>
        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="退款金额">
          <a-input-number
            style="width: 200px"
            placeholder="请输入退款金额单位（元），例：一分钱，输入：0.01"
            :formatter="(value) => `￥ ${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')"
            :min="0"
            v-model="refundData"
            :precision="2"
          />
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
// import {httpAction} from '@/api/manage'
import { getAction } from '@/api/manage'

export default {
  name: 'OrderModel',
  data() {
    return {
      title: '操作',
      visible: false,
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      confirmLoading: false,
      url: {
        send: '/mall/order/doRefund',
      },
      templateRsvno: '',
      templateOrderId: '',
      templateContent: '',
      // receiver: "",
      // msgType: "",
      refundData: '',
      sendParams: {},
    }
  },
  methods: {
    open(record) {
      this.sendParams.templateCode = record.templateCode
      this.templateContent = record.reason
      this.templateOrderId = record.id
      this.refundData = (record.payMoney/100).toFixed(2);
      this.visible = true
    },
    close() {
      this.templateRsvno = ''
      this.templateOrderId = ''
      this.refundData = ''
      this.sendParams = {}
      this.visible = false;
    },
    handleOk() {
      let that = this;
      let httpurl = that.url.send
      that.sendParams.orderId = that.templateOrderId;
      that.sendParams.money = Math.round(that.refundData * 100)
      that.confirmLoading = true
      
      that.$confirm({
        title: '确认退款',
        content: '是否退款' + that.refundData + '元?',
        onOk: function () {
          that.loading = true;
          getAction(httpurl, that.sendParams).then((res) => {
            if (res.success) {
              that.$message.success('退款成功');
              that.$emit('ok');
            } else {
              that.$message.warning(res.message)
            }
          })
          .finally(() => {
            that.loading = false;
            that.confirmLoading = false;
            that.close();
          })
        },
        onCancel() {
          that.confirmLoading = false
          that.close()
        },
      })
    },
    handleCancel() {
      this.close()
    },
  },
}
</script>

<style scoped>
</style>